package leetcode.problems;

import org.junit.Test;

/**
 * Created by gmwang on 2018/7/25
 * 字符串翻转
 */
public class _0807ReverseWordsInStringIII {
    /**
     *
     Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

     Example 1:
     Input: "Let's take LeetCode contest"
     Output: "s'teL ekat edoCteeL tsetnoc"
    /**
     *
     * @param s
     * @return
     */
    public String reverseWords(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        String[] strings = s.split(" ");
        int i =0;
        for(String s1:strings){
            StringBuilder stringBuilder1 = new StringBuilder(s1);
            stringBuilder.append(stringBuilder1.reverse());
            if(i != strings.length - 1)
            stringBuilder.append(" ");
            i++;
        }
        return stringBuilder.toString();
    }
    @Test
    public void test() {
//        int[] ints = {1};
//        int k = 0;
//        int[] ints = {0,10};
//        int k = 2;
        String s = "Let's take LeetCode contest";
        s = reverseWords(s);
        System.out.println(s);
    }
}
